package net.huashitong.Indicators.service;

import com.sirdc.modules.core.dao.BaseDao;
import com.sirdc.modules.sys.base.StringPKService;
import com.sirdc.modules.sys.service.SysTableService;
import net.huashitong.Indicators.dao.AreaCodeDao;
import net.huashitong.Indicators.entity.AreaCode;
import net.huashitong.Indicators.filter.AreaCodeFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class AreaCodeService extends StringPKService<AreaCode> {
    @Autowired
    private AreaCodeDao dao;

    @Override
    protected BaseDao<AreaCode, String> getDao() {
        return dao;
    }

    @Autowired
    private SysTableService tableService;


    /**
     * 条件查询
     * @param filter
     * @return
     */
    public List<AreaCode> queryAreaCode(AreaCodeFilter filter){
        return dao.queryAreaCode(filter);
    }

    @Override
    protected void beforeSave(AreaCode obj) {
        obj.setSysId(tableService.updateMaxSysId("BA01", null));
    }

    //*根据省份code获取地市

    public List<AreaCode> getCitysbyParentCode(String areacode)
    {
        return dao.getCitysByParentCode(areacode);
    }


    /**
     * 清空地区表
     * (很冒险的操作)
     */
    public void deleteAreaCode()
    {
        dao.deleteAreaCode();
    }
}
